home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3.iso / chapte22 / ex12.c < prev    next >
C/C++ Source or Header  |  1995-05-29  |  2KB  |  51 lines

  1. #include <genstub.c>
  2.  
  3. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4. {
  5.    static BOOL bAnsi = TRUE;
  6.    switch (uMsg)
  7.    {
  8.          case WM_COMMAND:
  9.                switch ( LOWORD( wParam ) )
  10.                {
  11.                      case IDM_TEST:
  12.                      {
  13.                         TCHAR szBuffer[128];
  14.                         static WCHAR wc[] = // Declare a Unicode string.
  15.                            L"This is an example of a wide-char string";
  16.                         static TCHAR tc[] = // Declare an ANSI string.
  17.                            "This is an example of a Mulitple-Bytes String";
  18.                         WCHAR wb[65]; // buffer for wide-chars.
  19.                         TCHAR tb[65]; // buffer for multiple-byte strings.
  20.                         HDC   hDC = GetDC( hWnd );
  21.  
  22.                         // Convert wide to multibyte ANSI.
  23.                         WideCharToMultiByte( CP_ACP, 0, wc, -1, tb, 64, NULL, NULL );
  24.                         TextOut( hDC, 0, 0, szBuffer, wsprintf( szBuffer,
  25.                                 "MultipleByte: %s", tc ) );
  26.                         TextOut( hDC, 0, 20, szBuffer, wsprintf( szBuffer,
  27.                                 "Converted WideChar: %s", tb ) );
  28.                         MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, tb, -1, wb, 64 );
  29.  
  30.                         // wide strings should be the same now.
  31.                         WideCharToMultiByte( CP_ACP, 0, wb, -1, tb, 64, NULL, NULL );
  32.  
  33.                         TextOut( hDC, 0, 40, szBuffer, wsprintf( szBuffer,
  34.                                  "Twice-Converted WideChar: %s", tb ) );
  35.  
  36.                         ReleaseDC( hWnd, hDC );
  37.                      }
  38.                      break;
  39.                      case IDM_EXIT:
  40.                            DestroyWindow( hWnd );
  41.                      break;
  42.                }
  43.                break;
  44.          case WM_DESTROY:
  45.                PostQuitMessage( 0 );
  46.                break;
  47.          default:
  48.                return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  49.    }
  50.    return( NULL );
  51. }